#include "seller.h"
#include <QDebug>

cs8Seller::cs8Seller(QObject *parent) :
    QObject(parent)
{
    m_totalSum=0;
}

QMap<QDateTime, sale *> cs8Seller::sales() const
{
    return m_sales;
}

void cs8Seller::addSale(const QDateTime &transaction, const QString &posName, int quantity, double price)
{

    sale *newSale=new sale(transaction,posName,quantity,price);
    qDebug() << "add sale " << "date: " << transaction.toString () << " POS " << posName << " Qty" << quantity << "Price" << price << " total" << newSale->total ();
    m_totalSum+=newSale->total ();
    m_sales.insertMulti (transaction,newSale);
}

void cs8Seller::clearSales()
{
    m_sales.clear ();
    m_totalSum=0;
}

double cs8Seller::totalSum()
{
    return m_totalSum;
}

void cs8Seller::setTotalSum(double total)
{
    m_totalSum=total;
}

void cs8Seller::setName(const QString &name)
{
    m_name=name;
}

QString cs8Seller::name() const
{
    return m_name;
}


sale::sale(const QDateTime &transaction, const QString &posName, int quantity, double price)
{
    m_transaction=transaction;
    m_pos=posName;
    m_quantity=quantity;
    m_price=price;
    m_total=(double)m_quantity*price;
}

double sale::total() const
{
    return m_total;
}

QDateTime sale::timeStamp() const
{
    return m_transaction;
}

int sale::quantity() const
{
    return m_quantity;
}

double sale::price() const
{
    return m_price;
}

QString sale::pos() const
{
    return m_pos;
}
